﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace Marmat.Forms.Skin
{
    /// <summary>
    /// 基于 Color 的扩展实例
    /// </summary>
    public static class ColorExtension
    {
        /// <summary>
        /// 获取两个颜色的叠加色
        /// </summary>
        /// <param name="baseColor">底层色</param>
        /// <param name="parentColor">顶层色</param>
        /// 来源:https://blog.csdn.net/aa13058219642/article/details/80953341
        /// <returns></returns>
        public static Color Blend(this Color baseColor, Color parentColor)
        {
            float a1 = parentColor.A;
            float a2 = baseColor.A - (a1 * baseColor.A) / 256;
            float a = a1 + a2;
            int R = Convert.ToInt32((a1 * parentColor.R + a2 * baseColor.R) / a);
            int G = Convert.ToInt32((a1 * parentColor.G + a2 * baseColor.G) / a);
            int B = Convert.ToInt32((a1 * parentColor.B + a2 * baseColor.B) / a);
            int A = Math.Min(Convert.ToInt32(a), 255);
            return Color.FromArgb(A, R, G, B);
        }
    }
}
